package service

import (
	"encoding/json"
	"rongyy/src/middlewares"
	"rongyy/src/models"
)

type BankService struct {
}

func (pc *BankService) Info() ([]models.BankInfoModel, int64, error) {
	data, total, err := (&models.BankInfoModel{}).Query()
	if err != nil {
		middlewares.Logger.Println("Unmarshal resp3013 failed ", err)
		return nil, 0, err
	}
	return data, total, nil
}

func (pc *BankService) Bind(req *models.ReqBindBank) (*models.RespBindBankCard, error) {
	data, err := (&HisService{}).BindBankCard(req)
	if err != nil {
		middlewares.Logger.Println("Unmarshal resp3013 failed ", err)
		return nil, err
	}
	d := &models.RespBindBankCard{}
	err = json.Unmarshal(data, d)
	if err != nil {
		middlewares.Logger.Println("Unmarshal Resp32004 failed ", err)
		return nil, err
	}
	middlewares.Logger.Println("Unmarshal resp3013 failed ", data)
	return d, nil
}

func (pc *BankService) UnBind(req *models.ReqUnBindBank) (*models.RespBindBankCard, error) {
	data, err := (&HisService{}).UnbindBankCard(req)
	if err != nil {
		middlewares.Logger.Println("Unmarshal resp3013 failed ", err)
		return nil, err
	}
	d := &models.RespBindBankCard{}
	err = json.Unmarshal(data, d)
	if err != nil {
		middlewares.Logger.Println("Unmarshal Resp32004 failed ", err)
		return nil, err
	}
	middlewares.Logger.Println("Unmarshal resp3013 failed ", data)
	return d, nil
}

func (pc *BankService) QueryBankCard(req *models.ReqQueryBank) (*models.RespQueryBank, error) {
	data, err := (&HisService{}).QueryBankCard(req)
	if err != nil {
		middlewares.Logger.Println("Unmarshal resp3013 failed ", err)
		return nil, err
	}
	middlewares.Logger.Println("Unmarshal resp3013 failed ", data)
	return data, nil
}
